﻿using RepositoryFramework;

namespace Portal.Repository
{
	/// <summary>
	/// Class <see cref="PortalUnitOfWork"/> define unit of work
	/// </summary>
	public class PortalUnitOfWork : UnitOfWork, IPortalUnitOfWork
	{
		#region Fields

		private IContactInfoRepository _contactInfoRepository;
		private IUserRepository _userRepository;

		#endregion Fields

		#region Properties

		/// <summary>
		/// Gets the contact information repository.
		/// </summary>
		/// <value>
		/// The contact information repository.
		/// </value>
		public IContactInfoRepository ContactInfoRepository
		{
			get
			{
				if (_contactInfoRepository == null)
				{
					_contactInfoRepository = new ContactInfoRepository(Connection);
				}
				return _contactInfoRepository;
			}
		}

		/// <summary>
		/// User repository
		/// </summary>
		public IUserRepository UserRepository
		{
			get
			{
				if (_userRepository == null)
				{
					_userRepository = new UserRepository(this);
				}
				return _userRepository;
			}
		}

		#endregion Properties

		#region .ctor

		/// <summary>
		/// Initializes a new instance of the <see cref="UnitOfWork"/> class.
		/// </summary>
		public PortalUnitOfWork(string connectionString)
			: base(connectionString)
		{
		}

		#endregion .ctor
	}
}